<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .upload{
            height: 100px;
            line-height: 100px;
            text-align: center;
            width: 100px;
            border: 1px solid #ddd;
            position: relative;
        }
        .plus{
            font-size: 28px;
        }
        input{
            top: 0;
            left: 0;
            position: absolute;
            width: 100px;
            height: 100px;
            opacity: 0;
        }
    </style>
</head>
<body>
    <div class="upload">
        <span class="plus">+</span>
        <input type="file" id="input" accept=".jpg, .jpeg .png">
    </div>
    <img src="" alt="" id="img">
</body>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>
    document.getElementById("input").addEventListener("change",function (e) {
            console.log(e.target.files);//伪数组
            Array.from(e.target.files).map((f=>{
                let formData = new FormData();
                formData.append("file",f);
                axios.post("http://linweiqin.cn:8001/v1/addimg/avatar",formData).then(res=>{
                    console.log(res);
                    let imageUrl = "http://linweiqin.cn:8001/img/" + res.data.image_path;
                    document.getElementById("img").setAttribute("src",imageUrl)
                })
            }))
    })
</script>
</html>